﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AddressBook.DAO;
using AddressBook.Entity;
using System.Text;

public partial class GetAllContacts : System.Web.UI.Page
{
    static Base_EmployeeDAO dao = new Base_EmployeeDAO();

    protected void Page_Load(object sender, EventArgs e)
    {
        ResultEntity result = new ResultEntity();
        result.Name = "Contacts";

        if (!string.IsNullOrEmpty(Request.QueryString["compid"]) && !string.IsNullOrEmpty(Request.QueryString["phone"]))
        {
            StringBuilder sb = new StringBuilder();
            //获取该公司所有的用户数据，但是剔除已被删除的用户
            List<Base_Employee> contacts = dao.GetInfos(" * ", " where isDelete = 0 and Left(DeptID,4) = '" + Request.QueryString["compid"].Substring(0, 4) + "'", string.Empty, string.Empty);
            foreach (Base_Employee employee in contacts)
            {
                sb.Append("{");
                sb.AppendFormat("\"EmployID\":\"{0}\",", employee.EmployID);
                sb.AppendFormat("\"FstName\":\"{0}\",", employee.FstName);
                sb.AppendFormat("\"SecName\":\"{0}\",", employee.SecName);
                sb.AppendFormat("\"Phone\":\"{0}\",", employee.Phone);
                sb.AppendFormat("\"DeptID\":\"{0}\",", employee.DeptID);
                sb.AppendFormat("\"Address\":\"{0}\",", employee.Address);
                sb.AppendFormat("\"Email\":\"{0}\",", employee.Email);
                sb.AppendFormat("\"FamiryTel\":\"{0}\",", employee.FamiryTel);
                sb.AppendFormat("\"Fax\":\"{0}\",", employee.Fax);
                sb.AppendFormat("\"HeadUrl\":\"{0}\",", employee.HeadUrl);
                sb.AppendFormat("\"Sex\":\"{0}\",", employee.Sex);
                sb.AppendFormat("\"Station\":\"{0}\",", employee.Station);
                sb.AppendFormat("\"Tel\":\"{0}\"", employee.Tel);
                sb.Append("},");
            }
            if (sb.Length > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }

            result.ResultCode = "0";
            result.Contents = sb.ToString();
        }
        else
        {
            result.Desc = "参数不正确！";
            result.ResultCode = "-2";
        }

        Response.Write(Common.ReturnResult(result));
    }
}